package at.fhj.itm.generator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import at.fhj.itm.metadata.Column;
import at.fhj.itm.metadata.Table;

/**
 * Class for storage of the mapping between columns and their value for code generation
 * 
 * @author Seuchter
 *
 */
public class ColumnValueMapping<C extends Column, V> {

	
	private List<ColumnValuePair<C, V>> mappings;
	private Map<String, ColumnValuePair<C, V>> namePairMap;
	
	
	public ColumnValueMapping(){
		mappings = new ArrayList<ColumnValuePair<C, V>>();
		namePairMap = new HashMap<String, ColumnValuePair<C, V>>();
		
	}
	public List<ColumnValuePair<C, V>> getMapping(){
		return Collections.unmodifiableList(mappings);
	}
	public void updateBinding(String columnName, V value){
		if(!namePairMap.containsKey(columnName)){
			return;
		}
		
		namePairMap.get(columnName).setValue(value);
	}
	public void addMapping(C column, V value){
		addMapping(column, value, true);
	}
	public void addMapping(C column, V value, boolean quoteValue){
		ColumnValuePair<C, V> mapping = new ColumnValuePair<C,V>(column, value, quoteValue);
		mappings.add(mapping);
		namePairMap.put(column.getName(), mapping);
	}
	
	
}
